﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClasesLibreria.dominio;
using System.Data.SqlClient;

namespace ClasesLibreria.dao
{
    public static class DAOProveedor
    {
        public static void insertProveedor(Proveedor proveedor, string connectionString)
        { }

        public static void updateProveedor(Proveedor proveedor, string connectionString)
        { }

        public static void deleteProveedor(Proveedor proveedor, string connectionString)
        { }

        public static List<Proveedor> getList(string connectionString)
        {
            SqlConnection conn;
            SqlCommand cmd;
            SqlDataReader dr;
            List<Proveedor> proveedores = new List<Proveedor>();


            conn = new SqlConnection();
            conn.ConnectionString = connectionString;
            conn.Open();
            cmd = new SqlCommand(
                                "  SELECT NroProveedor, Cuit, RazonSocial, Telefono, FechaAlta, FechaBaja, " +
                                "         Email, Barrio, Calle, Numero, Piso, CodigoPostal " +
                                "    FROM Proveedor " +
                                "ORDER BY NroProveedor"
                );
            cmd.Connection = conn;
            dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                Proveedor proveedor = new Proveedor();
                proveedor.Id = int.Parse(dr["NroProveedor"].ToString());
                proveedor.Cuit = dr["Cuit"].ToString();
                proveedor.RazonSocial = dr["RazonSocial"].ToString();
                proveedores.Add(proveedor);
            }
            conn.Close();
            return proveedores;
        }

        public static Proveedor getById(int id, string connectionString)
        { return new Proveedor(); }

    }
}
